package 算法.leetcode.labuladong.数组和链表;

import 算法.leetcode.offer.base.ListNode;

/**
 * @author lchenglong
 * @date 2022/6/16
 */
public class 删除排序链表中的重复元素 {
    class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            //边界条件
            if (head == null)return null;
            // 定义快慢指针
            ListNode fast = head,slow = head;
            while (fast!=null){
                if (fast.val == slow.val){
                    slow.next = fast;
                    slow = slow.next;
                }
                fast = fast.next;
            }
            // 断开与后面重复元素的连接
            slow.next = null;
            return head;
        }
    }
}
